package console

import (
	"gin-demo/common"
	"gin-demo/container"
	"gin-demo/service/console"
	"github.com/gin-gonic/gin"
	"strconv"
)

func AddConsoleClusterRouter(engine *gin.Engine) {

	group := engine.Group("console")
	{
		group.GET("/cluster/list", clusterList)
	}
}

// @Summary 管控接口
// @Description 获取集群列表
// @Tags console
// @Accept application/json
// @Produce application/json
// @Success 200 {object} common.Response
// @Failure 400 {object} common.Response
// @Failure 500 {object} common.Response
// @Router /console/cluster/list [get]
func clusterList(context *gin.Context) {

	pageNum, _ := strconv.Atoi(context.Query("pageNum"))
	pageSize, _ := strconv.Atoi(context.Query("pageSize"))
	var pageRequest common.PageRequest
	pageRequest.PageNum = pageNum
	pageRequest.PageSize = pageSize
	service := container.Get("clusterService").(console.ClusterServiceImp)
	list, err := service.List(pageRequest)
	response := common.NewCommonResponse()
	if err != nil {
		response.Code = common.CodeClusterListFail
		response.Message = common.MsgClusterListFail
	}

	response.Data = list
	context.JSON(response.Code, response)
}
